// query-log.js
import request from "@/util/request.js";

async function fetchUserActions(userId) {
    try {
        const res = (await request.get(`/userActions/user/${userId}`)).data;

        console.log("完整响应数据:", res); // 👈 调试用：查看返回结构
        console.log("响应状态:", res.status);

        if (res.code === 200) {
            if (res.data && res.data.length > 0) {
                const SuZu = res.data.map(item => ({
                    id: item.id,
                    userId: item.userId,
                    actionTime: item.actionTime,
                    actionContent: item.actionContent
                }));
                console.log("SuZu:", SuZu);
                return SuZu;
            } else {
                console.warn("该用户暂无操作记录");
                return [];
            }
        } else {
            console.error("接口请求失败:", res.data.message || "未知错误");
            return [];
        }
    } catch (error) {
        console.error("获取用户操作记录失败:", error);
        alert("获取用户操作记录失败");
        return [];
    }
}

export { fetchUserActions };